import Skype4Py
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
import xmlrpclib


class SkypeService:
    def __init__(self):
        skype=Skype4Py.Skype()
        if not skype.Client.IsRunning:
            skype.Client.Start()
        skype.Attach()
        status = skype.AttachmentStatus
        skype.Convert.AttachmentStatusToText(status)
        print 'API attachment status: '+ skype.Convert.AttachmentStatusToText(status)
        if status==Skype4Py.apiAttachAvailable:
            skype.Attach()
        print 'API attachment status2: '+ skype.Convert.AttachmentStatusToText(status)
        if status==Skype4Py.apiAttachSuccess:
            app=skype.Application('transferfile')
            app.Create()
    
    def sendmessage(self, text, user):
        #app.connect(username)
        #app.Streams[0].write(text)
        print "send message:" + text + " to " + user
        return True
        
    def broadcast(text):
        return True
    def getuserlist(text):
        return ['rui','xiao']
    
myService = SimpleXMLRPCServer(("localhost", 62750))          
myService.register_introspection_functions()     
skypeService_object = SkypeService()               
myService.register_instance(skypeService_object)
print "skype service is running(port 62750):"
myService.serve_forever()